<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  name: 'LineChart',
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart1'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    item: {
      type: Object
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        title: {
          text: '课堂心率曲线',
          textStyle: {
            color: 'black',
            fontWeight: 'bold'
          }

        },
        backgroundColor: 'white',
        tooltip: {
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          },
          trigger: 'axis',
          formatter: function(param) {
            console.log(param)
            param = param[0]
            // console.log(param)
            return [
              '心率' + '<br/>' + '<hr size=1 style="margin: 3px 0">' +
              '<h1 style="font-size:14px;color:white;margin:0 25px 0 0">' + param.data + '</h1>'
            ].join('')
          }
        },
        // visualMap: {
        //     top: 10,
        //     right: 10,
        //     pieces: [{
        //         gt: 0,
        //         lte: 50,
        //         color: '#CCCCCC'
        //     }, {
        //         gt: 50,
        //         lte: 100,
        //         color: '#39ACFF'
        //     }, {
        //         gt: 100,
        //         lte: 150,
        //         color: '#6DD401'
        //     }],
        //     outOfRange: {
        //         color: '#999'
        //     }
        // },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],
          axisLine: {
            lineStyle: {
              color: '#CCCCCC'
            }
          },
          axisLabel: {
            textStyle: {
              color: 'black'// 坐标值得具体的颜色
            }
          }
        },
        yAxis: {
          splitLine: {
            show: true,
            lineStyle: {
              type: 'dashed'
            }
          },
          axisLine: {
            lineStyle: {
              color: 'white'
            }
          },
          axisLabel: {
            textStyle: {
              color: 'black'// 坐标值得具体的颜色

            }
          }
        },
        series: [
          {
            data: [10, 20, 50],
            type: 'line',
            areaStyle: {
              // color:'#CCCCCC',
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#CCCCCC'
                }, {
                  offset: 1,
                  color: '#FFFFFF'
                }])
              }
            },
            itemStyle: {
              color: '#CCCCCC', // 折点颜色
              normal: {
                lineStyle: {
                  color: '#CCCCCC' // 折线颜色
                }
              }
            }
          },
          {
            data: ['-', '-', 50, 60, 80, 100],
            type: 'line',
            areaStyle: {
              // color:'#39ACFF',
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#39ACFF'
                }, {
                  offset: 1,
                  color: '#FFFFFF'
                }])
              }
            },
            itemStyle: {
              normal: {
                color: '#39ACFF', // 折点颜色
                lineStyle: {
                  color: '#39ACFF' // 折线颜色
                }
              }
            }
          },
          {
            data: ['-', '-', '-', '-', '-', 100, 110, 120, 130],
            type: 'line',
            areaStyle: {
              // color:'#6DD401',
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#6DD401'
                }, {
                  offset: 1,
                  color: '#FFFFFF'
                }])
              }
            },
            itemStyle: {
              color: '#6DD401', // 折点颜色
              normal: {
                lineStyle: {
                  color: '#6DD401' // 折线颜色
                }
              }
            }
          }
        ]
      })
    }
  }
}
</script>
